import time
from common_1.Ultils import ForumDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class ForumReplyPM:
    url=""
    driver=""
    def __init__(self):
        url="http://127.0.0.1:9580/index.html?theme=light"
        self.driver=ForumDriver.driver
        self.driver.get(url)

    def ForumReplyPMTest(self):
        # 点击“消息通知“图标按钮
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a").click()
        # "所有站内信"是否全部显示
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message")
        # 点击其中一条消息进行回复
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(4) > div > div.col.text-truncate > a > span:nth-child(2)").click()
        # 识别弹窗页面
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_reply_modal > div > div > div.modal-header")
        # 点击回复
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_message_reply").click()
        # # 发送内容——发送对话框加载出现后
        # Reply_dialog = WebDriverWait(self.driver,15).until(
        #     EC.visibility_of_element_located((By.CSS_SELECTOR,"#index_message_reply_receive_content"))
        # )
        # Reply_dialog.send_keys("hello")

        # 等待弹窗主体加载完成——重点
        WebDriverWait(self.driver, 15).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, "#index_message_reply_div"))
        )
        # 再定位输入框
        Reply_dialog = WebDriverWait(self.driver, 15).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "#index_message_reply_receive_content"))
        )
        Reply_dialog.click()
        Reply_dialog.send_keys("hello")

        # 点击发送按钮
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message_reply").click()
        # 静置发送成功的时间
        time.sleep(5)